package flst.ipiweb.struts.action.envoicolis;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import flst.ipiweb.service.ServiceCommande;
import flst.ipiweb.transverse.Commande;
import flst.ipiweb.transverse.IPIException;

public class EnvoiColisAction extends Action{
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form,
			HttpServletRequest request, 
			HttpServletResponse response)
			throws Exception {
		
			//On récupère la session
			HttpSession session = request.getSession();
			if(session.getAttribute("login") == null)
			{
				return mapping.findForward("login");
			}
		
			String numCommande = "";
			if(request.getParameter("recherche") != null)
			{
				numCommande = request.getParameter("recherche");
				ServiceCommande sCommande = new ServiceCommande();
				
				try
				{
					Commande commande = sCommande.rechercherCommande(numCommande);
					request.setAttribute("commande", commande);
				}
				catch(IPIException e)
				{
					System.out.println(e.getMessage());
				}
			}
			
			
			
			request.setAttribute("pageTitle", "envoicolis.title");
			HashMap<String, String> onglet = new HashMap<String, String>();
			onglet.put("envoicolis", "active");
			request.setAttribute("onglet", onglet);

			return mapping.findForward("envoi_colis");
		}

}
